import v4l2
import fcntl
import cv2

vd = open('/dev/video0', 'rb')
#with open('a.log', 'w') as fp:
#    fp.write(str(dir(v4l2)))

cp = v4l2.v4l2_capability()
fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCAP, cp)
#print(cp)

st = v4l2.v4l2_control()
st.id = v4l2.V4L2_CID_FOCUS_AUTO
st.value = False
fcntl.ioctl(vd, v4l2.VIDIOC_G_CTRL, st)

fmt = v4l2.v4l2_format()
fmt.type = v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE
fmt.fmt.pix.width = 1280
fmt.fmt.pix.height = 960
fmt.fmt.pix.pixelformat = v4l2.V4L2_PIX_FMT_JPEG
fcntl.ioctl(vd, v4l2.VIDIOC_S_FMT, fmt)

print(vd)
img = vd.read(1)
print(img)
